<?php
/*
Plugin Name: BPDEV-ADMIN-MENU
Plugin URI: http://bp-dev.org/projects/#admin
Description: It shows a menu for BPDEV plugins and not
Author: Nicola Greco
Version: 0.3
Author URI: http://nicolagreco.com

Copyright (c) 2009-2011, Nicola Greco (mail: notsecurity@gmail.com | website: http://nicolagreco.com).

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

define( 'BPDEV_ADMIN_MENU_VERSION', '0.3' );

require_once( 'bpdev-core.php' );

function bpdev_admin_menu() {

   if(is_site_admin()){
	   add_menu_page(
	   	'BPDEV Admin',
	   	'BPDEV Admin',
		   2, 
		   'bpdev-admin-menu', 
		   'bpdev_admin_menu_first',
		   '/wp-content/mu-plugins/bpdev-admin/images/icon.png'
	      );

	   add_submenu_page(
		   'bpdev-admin-menu',
	     	'Plugins',
		   'Plugins',
		   1,
		   'bpdev-plugins',
		   'bpdev_admin_plugins'
	   );
   }
}

function bpdev_admin_plugins() {

	if ( isset( $_POST['submitted'] ) ) {

		do_action( 'bpdev_admin_plugins_save' );
		echo "<div id=\"message\" class=\"updated fade\"><strong>Options updated.</strong></div>";

	}

	?>

	<div class="wrap">

		<h2><?php _e( 'Plugins', 'buddypressdev' ) ?></h2>
		<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post" id="options">

	<?php do_action( 'bpdev_admin_plugins_screen' ); ?>

			<p class="submit">

				<input name="submitted" type="hidden" value="yes" />
				<input type="submit" name="bpdev-admin-plugins-submit" id="bpdev-admin-plugins-submit" value="<?php _e( 'Save Settings', 'buddypressdev' ) ?>"/>

			</p>
				<?php wp_nonce_field( 'bpdev-admin-plugins' ) ?>
		</form>

	</div>

	<?php
}

function bpdev_admin_menu_first() {

	?>
<div class="wrap">

	<div class="icon32" id="icon-plugins"><br/></div>

	<h2>BuddyPressDEV Admin Menu</h2>

	<p>With this plugin you can set you 3rd parts plugins, and check for new BPDEV Plugins.</p>

	<h3 id="currently-active">Last Plugins on <a href="http://bp-dev.org/plugins/">BPDEV</a></h3>

	<div class="clear"/>

	<?php

	if ( function_exists('simplepie_init') ) { 
		simplepie_init();

	?>
	<table cellspacing="0" id="active-plugins-table" class="widefat">
		<thead>
		<tr>
			<th scope="col">Plugin</th>
			<th class="num" scope="col">Download</th>
			<th scope="col">Description</th>
		</tr>
		</thead>

		<tfoot>
		<tr>
			<th scope="col">Plugin</th>
			<th class="num" scope="col">Download</th>
			<th scope="col">Description</th>
		</tr>
		</tfoot>

		<tbody class="plugins">
	<?php

		$rss = new SimplePie("http://bp-dev.org/category/plugins/feed/");
		if ( $rss ) $items = array_slice( $rss->get_items() , 0 , 5 );

		foreach ( $items as $item ) {
				$author = $item->get_author();

	?>

		<tr class="active">
			<td class="name"><a title="Visit <?php echo $item->get_title(); ?> Home Page" href="<?php echo $item->get_link(); ?>"><?php echo $item->get_title(); ?></a></td>
			<td class="vers"><a href="<?php echo $item->get_link(); ?>">Download</a></td>
			<td class="desc"><p><?php echo $item->get_content(); ?><!-- By <a title="Visit author homepage" href="<?php echo $item->get_link(); ?>"><?php echo $author->get_name(); ?></a>.--></p></td>
		</tr>

	<?php
		}
	?>
		</tbody>
	</table>
	
	<p>If something goes wrong with a plugin and you can contact developers on <a href="http://bp-dev.org/forums">BPDEV Forums</a>.</p>

	<?php

	} else {

	?>

	<?php } ?>

	<h2>Get More Plugins</h2>

	<p>You can find additional plugins for your site by visiting <a href="plugin-install.php">BuddyPressDEV Plugin Directory</a>.  If you wrote a plugin, please add it filling out <a href="http://bp-dev.org/add-plugin/">this form</a>.</p>
	<p>If you're looking for . WordPress Plugin, you can find theme in <a href="http://wordpress.org/extends/plugins">WordPress Plugin Directory</a></p>
</div>

	<?php

}

function bpdev_admin_save_component( $component, $blog = true ) {

	$option =  $_POST[$component];
	if ( isset( $_POST[$component] ) )
		if ( $blog )
			update_option( $component, $option );
		else
			update_site_option( $component, $option );

}

add_action( 'bpdev_admin_save_component' , 'bpdev_admin_save_component' , 1 , 2 );
add_action( '_admin_menu' , 'bpdev_admin_menu' );

?>